<#assign ctx= request.contextPath/>
<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head>
    <title>DownUp Service!</title>
    <meta charset="utf-8">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width">
    <link rel="stylesheet" href="${ctx}/eureka/css/wro.css">
    <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>
</head>
<body id="one">
<#include "header.ftl">

<form method="post">
    <p>
        <span>username：</span> <input type="text" id="username" name="username">
    </p>
    <p>
        <span>password</span> <input type="password" id="password" name="password">
    </p>
    <button type="submit" id="loginSubbmit">login</button>
</form>

<script type="text/javascript">


    $("#loginSubbmit").click(function () {
        var password = document.getElementById("password").value;
        var username = document.getElementById("username").value;
        var user = {
            "password": password,
            "username": username
        }
        console.log(user);
        $.ajax({
            url: "${ctx}/login",
            type: 'POST',
            data: JSON.stringify(
                user
            ),  // 直接丢对象
            // ajax传文件 一定要指定两个关键性的参数
            contentType: 'application/json',  // 不用任何编码 因为formdata对象自带编码 django能够识别该对象
            processData: false,  // 告诉浏览器不要处理我的数据 直接发就行
            success: function (data) {
                var success = data.msg;
                console.log(success);
                if (success == "success"){
                    console.log("登录成功");
                    var tokenVal = data.data.token;
                    var expireDate = new Date();
                    var eightHours = 60 * 60  * 1000 * 8;
                    expireDate.setTime(expireDate.getTime() + 30 * 60 * 1000 + eightHours);
                    console.log(expireDate.toTimeString());
                    document.cookie = "token=" + tokenVal + ";expires=" + expireDate.toGMTString() + ";path=/";
                    window.location.href = "${ctx}/localService/serviceServerMap"
                }
            }
        })

        return false;
    })

    function check() {
        var username = $("#username");
        // var inputPassword = $("#input-password");
        // md5Password.value = md5(inputPassword.value);
        var password = $("#password");
        return true;
    }


    function loginSubbmit() {
        var formData = new FormData();
        var password = document.getElementById("password").value;
        var username = document.getElementById("username").value;
        var user = {
            "password": password,
            "username": username
        }
        console.log(user);
        $.ajax({
            url: "${ctx}/login",
            type: 'POST',
            data: JSON.stringify(
                user
            ),  // 直接丢对象
            // ajax传文件 一定要指定两个关键性的参数
            contentType: 'application/json',  // 不用任何编码 因为formdata对象自带编码 django能够识别该对象
            processData: false,  // 告诉浏览器不要处理我的数据 直接发就行
            success: function (data) {
                console.log(data);
            }
        })
    }

</script>
</body>
</html>